package com.example.a14110100409.yuejiandemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.config.Config;
import com.example.a14110100409.yuejiandemo.javabean.ListResult_1;
import com.example.a14110100409.yuejiandemo.model.Model;
import com.example.a14110100409.yuejiandemo.service.ActImpls;

import it.sephiroth.android.library.picasso.Picasso;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class ActDetailActivity extends AppCompatActivity {
    private TextView act_detail_title,act_detail_Info,act_detail_address,act_detail_time,
            act_detail_price,act_detail_num,act_detail_tel,act_detail_intro;
    private ImageView act_detail_pic;
    private  String Id,aduprice,stuprice;
    private Button join;
    private Call<ListResult_1> call;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_act_detail);
        init();
        setInfo();
        event();
    }

    private void setInfo() {
        Retrofit retrofit= Model.getConn();
        ActImpls impls=retrofit.create(ActImpls.class);
        call=impls.getActInfo(Id);
        call.enqueue(new Callback<ListResult_1>() {
            @Override
            public void onResponse(Call<ListResult_1> call, Response<ListResult_1> response) {
                ListResult_1 info=response.body();
                act_detail_title.setText(info.getActivity_name());
                act_detail_Info.setText(info.getUpdate_time()+""+info.getClub_name());
                Picasso.with(ActDetailActivity.this).load(Config.PIC_URL+info.getThumb()).into(act_detail_pic);
                act_detail_address.setText("地址："+info.getProvince_name()+""+info.getCity_name()+""+info.getPlace());
                act_detail_price.setText("活动收费："+info.getActivity_price()+"/人");
                aduprice = info.getActivity_price().toString();
                stuprice = info.getActivity_price_stu().toString();
                act_detail_num.setText("已报名人数："+info.getSign_num()+"人");
                act_detail_tel.setText("报名热线："+info.getContact_tel());
                String s=info.getIntroduction().replaceAll("<p>","");
                s=s.replaceAll("</p>","");
                act_detail_intro.setText(s);
                act_detail_time.setText("时间："+info.getUpdate_time());
            }

            @Override
            public void onFailure(Call<ListResult_1> call, Throwable t) {
                Toast.makeText(ActDetailActivity.this,"信息获取失败",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void event() {
        join.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(ActDetailActivity.this,ActJoinActivity.class);
                i.putExtra("act_id",Id);
                i.putExtra("aduprice",aduprice);
                i.putExtra("stuprice",stuprice);
                startActivity(i);
            }
        });

    }

    private void init() {
        Intent intent=getIntent();
        Id=intent.getStringExtra("act_id");
        join=(Button)findViewById(R.id.act_detail_join);
        act_detail_address=(TextView)findViewById(R.id.act_detail_address);
        act_detail_title=(TextView)findViewById(R.id.act_detail_title);
        act_detail_Info=(TextView)findViewById(R.id.act_detail_Info);
        act_detail_time=(TextView)findViewById(R.id.act_detail_time);
        act_detail_price=(TextView)findViewById(R.id.act_detail_price);
        act_detail_num=(TextView)findViewById(R.id.act_detail_num);
        act_detail_tel=(TextView)findViewById(R.id.act_detail_tel);
        act_detail_intro=(TextView)findViewById(R.id.act_detail_intro);
        act_detail_pic=(ImageView) findViewById(R.id.act_detail_pic);
    }
}
